Skip to content

Warn about dates that may be real in the privacy check - #187

Merged
tompollard merged 2 commits into
mainfrom
feature/date-privacy-check
Oct 20, 2026
Merged

tompollard merged 2 commits into
mainfrom
feature/date-privacy-check

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

The README and check_privacy docstring said the privacy check looked for date patterns, but no date check existed. This adds one.

  • Report dates from the last 200 years up to today as possibly real, since de-identified datasets usually shift dates (often into the future). Future dates are treated as shifted and not reported.
  • Find written dates in CSV cells and .txt files: year-first (2023-01-13, with optional time), day- or month-first with a four-digit year (13/01/2023), and month names (13 Jan 2023, January 13, 2023, Jan 2023). Sentence-ending dates are included.
  • Read Unix seconds and milliseconds only in columns with time-like names (charttime, timestamp, ts, event_time), in a layout's timestamp columns, and in metadata rows such as Empatica E4 start times. IDs and counters have the same shape, so other numeric columns are not read as timestamps.
  • Skip two-digit years, compact dates (20230113), times without a date, and years on their own.
  • Report one warning per file, listing each column and its date range. Every warning is kept in the results and saved reports, tagged with the code possible-real-date. The terminal shows the first 10 per category and counts the rest.
  • Add ValidationConfig.date_lookback_years (default 200). It accepts a whole number from 1 to 1000, or None to turn the check off; other values raise ValueError.
  • Name E4 metadata rows (start_time, sample_rate) so warnings point at the start time.
  • Move E4 test fixtures to timestamps in 2150, as a date-shifted dataset would have, so format tests stay independent of the date check.

Notes

  • Datasets with dates shifted into the past will still be warned about, since format alone cannot tell shifted dates from real ones.
  • Documentation text files can be flagged; for example, the MIMIC-IV demo LICENSE.txt contains a 1996 date.
  • Compressed CSVs (.csv.gz) are not scanned by any check; that is unchanged here.

Verification

  • pytest -q: 257 passed, 1 skipped
  • git diff --check: passed
  • Decompressed MIMIC-IV demo tables (about 800,000 rows, dates shifted to the 2100s): no date warnings
  • Privacy check on a 50,000-row numeric CSV: 0.12s to 0.20s with default sampling

The README and check_privacy docstring said dates were checked, but no
date check existed. Add one: dates between date_lookback_years ago (200
by default) and today are reported as possibly real, since de-identified
datasets usually shift dates. Future dates are treated as shifted.

Written dates are found in CSV cells and text files. Unix seconds and
milliseconds are only read in columns with time-like names, or in layout
timestamp columns and metadata rows such as E4 start times, because IDs
and counters have the same shape. Each file gets one warning listing its
columns and date ranges; after 10 files the rest are summarized.

E4 test fixtures now use timestamps shifted to 2150, so format tests stay
independent of the date check.
…ding

A day- or month-first date followed by a full stop ("13/01/2023.") was
missed. A trailing period is now allowed; a decimal extension still is not.

date_lookback_years must be a whole number from 1 to 1000 or None.
Negative values silently matched nothing, 0 turned the check off, and very
large values raised an error partway through validation.

Every file with possible real dates now keeps its own warning, tagged with
the code "possible-real-date", so JSON and Markdown reports list them all.
Only the terminal output is shortened, to 10 warnings of one kind per
category plus a count of the rest.
@tompollard
tompollard merged commit 155caa9 into main Oct 20, 2026
2 checks passed
@tompollard
tompollard deleted the feature/date-privacy-check branch October 20, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant